


import math



def sortedr(r):
    l = len(r) / 3
    sr = [0.0] * (l * (l - 1)/2)
    index = 0
    for i in range(l - 1):
        for j in range(i + 1, l):
            d = math.sqrt((r[i * 3 + 0] - r[j * 3 + 0]) ** 2 + 
                          (r[i * 3 + 1] - r[j * 3 + 1]) ** 2 +
                          (r[i * 3 + 2] - r[j * 3 + 2]) ** 2)
            sr[index] = d
            index += 1
    sr.sort(reverse = True)
    return sr
    


def eq(sr1, sr2, cutoff = 0.1):
    if len(sr1) != len(sr2):
        return False
    for i in range(len(sr1)):
        if abs(sr1[i] - sr2[i]) > cutoff:
            return False
    return True
    
    

if __name__ == "__main__":
    r1 = [1.0, 2.0, 3.0, 9.0, 6.0, 32.0, 12.0, 22.0, 102.0, 1.0, 1.0, 1.0]
    r2 = [1.0, 2.0, 3.0, 9.0, 6.0, 32.0, 12.0, 22.0, 102.0, 1.0, 1.0, 1.7]
    sr1 = sortedr(r1)
    sr2 = sortedr(r2)
    print sr1
    print sr2
    print eq(sortedr(sr1), sortedr(sr2), 0.1)

            
    
